<link href="css/buttons.dataTables.min.css" rel="stylesheet">
<link href="css/select.dataTables.min.css" rel="stylesheet">

<div class="row">
    <div id="breadcrumb" class="col-md-12">
        <ol class="breadcrumb">
            <li><a href="#">用户管理</a></li>
            <li><a href="#">租客管理</a></li>
        </ol>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <div class="box-name">
                </div>
                <div class="box-icons">
                    <a class="expand-link">
                        <i class="fa fa-expand"></i>
                    </a>
                </div>
                <div class="no-move"></div>
            </div>
            <div class="box-content no-padding">
                <table class="table table-bordered table-striped table-hover table-heading table-datatable"
                       id="tenantListTable">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>电话</th>
                        <th>证件类型</th>
                        <th>证件号码</th>
                        <th>起租日期</th>
                        <th>结束日期</th>
                        <th>认证时间</th>
                        <th>详细信息</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                    <tfoot>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>电话</th>
                        <th>证件类型</th>
                        <th>证件号码</th>
                        <th>起租日期</th>
                        <th>结束日期</th>
                        <th>认证时间</th>
                        <th>详细信息</th>
                        <th>操作</th>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" role="dialog" id="formModel">
    <div class="modal-dialog" role="document" style="width: 800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">租户详细信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12" id="tenantInfo">
                            <h3>租客信息</h3>
                            <ul class="list-group">
                                <li class="list-group-item">姓名: <span id="name"></span></li>
                                <li class="list-group-item">证件类型: <span id="identityType"></span></li>
                                <li class="list-group-item">证件号码: <span id="identityCode"></span></li>
                                <li class="list-group-item">认证时间: <span id="authenticationTime"></span></li>
                                <li class="list-group-item">紧急联系人: <span id="urgent"></span></li>
                            </ul>
                            <h3>物业信息</h3>
                            <ul class="list-group" id="propertyInfo">

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
    var editTable;//全局的datatable变量

    //删除数据
//    $('#estateListTable tbody').on( 'click', 'button#delrow', function () {
//        var data = editTable.row($(this).parents('tr') ).data();
//        $.ajax({
//            type: "post",
//            async: false,
//            url: "statis.do",
//            data: {
//                action:"delete",
//                estateID:data[0]
//            },
//            dataType: "json", //返回数据形式为json
//            success: function (result) {
//                if (result.success) {
//
//                    $(result.jsonString).each(function () {
//                        tablePartSelect.append("<option value='" + this.id + "'>" + this.name + "</option>");
//                    });
//                } else {
//                    alert(result.errorMsg);
//                }
//            },
//            error: function (errorMsg) {
//                alert("服务器连接失败,请重试!");
//            }
//        });
//    });

    $('#tenantListTable tbody').on( 'click', 'button#delRow', function () {
        var comfirm=confirm("确定删除?");
        if(comfirm)
        {
            alert("删除成功");
        }
    });


    $('#tenantListTable').on( 'click', 'button#detailRow', function () {
        var data = editTable.row($(this).parents('tr') ).data();
        console.log(data);
        $("#tenantInfo #name").text(data.name);
        $("#tenantInfo #identityType").text(data.identityType);
        $("#tenantInfo #identityCode").text(data.identityCode);
        $("#tenantInfo #authenticationTime").text(data.authenticationTime);
        $("#tenantInfo #identityType").text(data.identityType);
        $("#tenantInfo #urgent").text(data.urgentName+"("+data.urgentPhone+")");
        var temp='<ul class="list-group">' +
                '<li class="list-group-item">物业编号: <span id="code">'+data.property.code+'</span></li>'+
                '<li class="list-group-item">物业地址: <span id="location">'+data.property.location+'</span></li>'+
                '<li class="list-group-item">状态: <span id="status">'+data.property.status+'</span></li>' +
                '<li class="list-group-item">物业面积: <span id="propertySquare">'+data.property.propertySquare+'</span></li>'+
                '</ul>';
        $("#propertyInfo").html(temp);
        $("#formModel").modal("show");//弹出框show

    });


    //初始化表格数据
    function initDataTable(){
        editTable=$('#tenantListTable').DataTable({
            "processing":true,
            "serverSide": true,
            "ajax":{
                "url": urlConfig.tenantList,
                "dataSrc": "jsonString"
            },
            "columnDefs": [{
                "targets": 0,
                "data": "tenantId",
                "visible": false,
                "orderable": false,
                "searchable": false

            },{
                "targets": 1,
                "data": "name",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 2,
                "data": "sex",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 3,
                "data": "phone",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 4,
                "data": "identityType",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 5,
                "data": "identityCode",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 6,
                "data": "startTime",
                "visible": true,
                "orderable": false,
                "searchable": true

            },{
                "targets": 7,
                "data": "endTime",
                "orderable": false,
                "searchable": true

            },{
                "targets": 8,
                "data": "authenticationTime",
                "orderable": false,
                "searchable": true

            },{
                "targets": 9,
                "data": null,
                "orderable": false,
                "searchable": false,
                "defaultContent":
                        "<button id='detailRow' class='btn btn-primary' type='button'>查看</button>"
            },{
                "targets": 10,//删除
                "data": null,
                "orderable": false,
                "searchable": false,
                "defaultContent":
                "<button id='editRow' class='btn btn-primary' type='button'>编辑</button>&ensp;" +
                "<button id='delRow' class='btn btn-primary' type='button'>删除</button>"
            }
            ],
            "aaSorting": [[ 1, "asc" ]],
            "autoWidth":false,
            "sDom":
                    "<'box-content'<'col-sm-6'f><'col-sm-6 text-right'l><'clearfix'>>rt<'box-content'<'col-sm-6'i><'col-sm-6 text-right'p><'clearfix'>>",
            "language": {
                "emptyTable":     "没有相关数据",
                "info": "显示 _START_ 到 _END_ 条, 共 _TOTAL_ 条记录",
                "infoEmpty":      "没有相关数据",
                "infoFiltered":   "(筛选自 _MAX_ 条记录)",
                "infoPostFix":    "",
                "thousands":      ",",
                "lengthMenu":     "每页显示 _MENU_ 条",
                "loadingRecords": "加载中",
                "processing":     "数据处理中",
                "search":         "搜索:",
                "zeroRecords":    "没有找到匹配数据",
                "paginate": {
                    "first":      "首页",
                    "last":       "末页",
                    "next":       "下一页",
                    "previous":   "上一页"
                },
                "aria": {
                    "sortAscending":  ":正序",
                    "sortDescending": ":倒序"
                }
            }
        });

    }
    $(document).ready(function() {
        $('#payTime').datepicker({setDate: new Date(),dateFormat:"yy-mm-dd",
            showButtonPanel:true,
            closeText:"关闭",
            yearSuffix: '年',
            currentText:'今天',
            showMonthAfterYear:true,
            monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
            dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
            dayNamesMin: ['日','一','二','三','四','五','六']
        });
        LoadDataTablesScripts(initDataTable);
    });
</script>
